package com.fjwt.gz.mgr.ctrl.agent;

import com.fjwt.gz.core.model.ApiRes;
import com.fjwt.gz.db.vo.AgentInfoVO;
import com.fjwt.gz.mgr.ctrl.CommonCtrl;
import com.fjwt.gz.service.impl.AgentInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/***
* 机构相关
*
*/
@Slf4j
@RestController
@RequestMapping("/api/subList")
public class AgentSubListController extends CommonCtrl {

    @Autowired private AgentInfoService agentInfoService;

    /**
     * 获取机构树
     */
    @GetMapping(value = "/queryOrgTree")
    public ApiRes queryOrgTree() {
        String agentNo = getValString("agentNo");
        log.info("pc端获取机构树接口，请求地址：/api/subList/queryOrgTree，请求参数：{}",  agentNo);
        AgentInfoVO agentTree = agentInfoService.getAgentInfos(agentNo);
//        log.info("pc端获取机构树接口，请求地址：/api/subList/queryOrgTree，返回结果：{}", JSONUtil.toJsonStr(agentTree));
        return ApiRes.ok(agentTree);
    }


    /**
     * 通过pid获取下级机构列表（只查询一级）
     */
    @GetMapping(value = "/querySubAgentList")
    public ApiRes querySubAgentList() {
        String agentNo = getValString("agentNo");
        log.info("pc端通过pid获取下级机构列表接口，请求地址：/api/subList/querySubAgentList，请求参数：{}",  agentNo);
        List<AgentInfoVO> subAgentList = agentInfoService.querySubAgentList(agentNo);
        return ApiRes.ok(subAgentList);
    }
}
